<?php

namespace app\api\controller;

use think\Controller;

class Experience extends Controller
{
    //留学生活
    public function experience()
    {
        $exper = model('common/Experience')
            -> order('create_time','desc')
            -> field('id,img,title,create_time')
            -> limit(2)
            -> select();
        if ($exper){
            return json(['code'=>100,'msg'=>'请求成功！','data'=>$exper]);
        } else {
            return json(['code'=>404,'msg'=>'请求失败！']);
        }
    }

    //留学实况
    public function experience_list()
    {
        $exper = model('common/Experience')
            -> order('create_time','desc')
            -> field('id,img,title')
            -> select();
        if ($exper){
            return json(['code'=>100,'msg'=>'请求成功！','data'=>$exper]);
        } else {
            return json(['code'=>404,'msg'=>'请求失败！']);
        }
    }

    //留学实况详情
    public function experience_content()
    {
        $exper = model('common/Experience')
            -> where('id',input('id'))
            -> field('title,author,create_time,num,content')
            -> find();
        $exper -> setInc('num');
        if ($exper){
            return json(['code'=>100,'msg'=>'请求成功！','data'=>$exper]);
        } else {
            return json(['code'=>404,'msg'=>'请求失败！']);
        }
    }

}
